EditorWindowDemo.cs (1688B)
1 using UnityEditor; 2 using UnityEngine.InputSystem; 3 4 public class EditorWindowDemo : EditorWindow 5 { 6 [MenuItem("Window/Input System Editor Window Demo")] 7 public static void Open() 8 { 9 GetWindow<EditorWindowDemo>(); 10 } 11 12 protected void OnGUI() 13 { 14 // Grab the current pointer device (mouse, pen, touchscreen). 15 var pointer = Pointer.current; 16 if (pointer == null) 17 return; 18 19 // Pointer positions should automatically be converted to EditorWindow space of 20 // the current window. Unlike player window coordinates, this uses UI window space, 21 // i.e. Y goes top down rather than bottom up. 22 var position = pointer.position.ReadValue(); 23 var pressure = pointer.pressure.ReadValue(); 24 var contact = pointer.press.isPressed; 25 26 EditorGUILayout.LabelField($"Device: {pointer}"); 27 EditorGUILayout.LabelField($"Position: {position}"); 28 EditorGUILayout.LabelField($"Pressure: {pressure}"); 29 EditorGUILayout.LabelField($"Contact?: {contact}"); 30 31 // Just for kicks, also read out some data from the currently used gamepad (if any). 32 var gamepad = Gamepad.current; 33 if (gamepad != null) 34 { 35 EditorGUILayout.Space(); 36 EditorGUILayout.LabelField($"Gamepad Left Stick: {gamepad.leftStick.ReadValue()}"); 37 EditorGUILayout.LabelField($"Gamepad Right Stick: {gamepad.leftStick.ReadValue()}"); 38 } 39 40 // We want to constantly refresh to show the current values so trigger 41 // another refresh right away. Otherwise, the values we show will only 42 // update periodically. 43 Repaint(); 44 } 45 }